package server.interfaces.impl;

import java.util.Vector;

import server.accessers.DataReaderListener;
import server.accessers.impl.DataReaderImpl;
import server.interfaces.SuscriberOperations;
import server.operations.Operation;

public class SuscriberImpl implements SuscriberOperations{
	private DataReaderImpl listener;
	private Vector<Operation> operations;
	public SuscriberImpl() {
		operations = new Vector<Operation>();
	}
	@Override
	public DataReaderListener getDataReaderListener() {
		return null;
	}
	
	public DataReaderImpl getDataReaderListener1() {
		return listener;
	}
	
	@Override
	public void publish(Operation operation) {
		operations.add(operation);
		if(listener != null)
			listener.signale();
	}
	@Override
	public Operation read() {
		if(operations.size() != 0)
			return operations.remove(0);
		return null;
	}
	@Override
	public void setDataReaderListener(DataReaderListener listener) {
		this.listener = null; 
	}
	public void setDataReaderListener1(DataReaderImpl listener) {
		this.listener = listener; 
	}
}
